package com.servlet;

import com.bean.*;
import com.dao.*;
import com.dao.impl.*;
import com.util.StringManipulation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/cheng/*")
public class ChenServlet extends BaseServlet {
    //跳转
    protected void CheTao(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UsecasetrueDao usecasetrueDao=new UsecasetrueDaoImpl();
        BhUserDao bhUserDao=new BhUserDaoImpl();
        try {
            HttpSession session=request.getSession();
           BhUser bhUser=(BhUser)session.getAttribute("BhSyUser");
            String url=request.getParameter("url");
          List<Usecasetrue> list= usecasetrueDao.queryUsecasetrue("select * from usecasetrue where cUrl='"+url+ "' and uId="+bhUser.getuID());
          List<Integer> list1=usecasetrueDao.getmap("select * from usecasetrue WHERE cUrl='"+url+"' and uID="+bhUser.getuID());
          System.out.println(list1);
          int cuowu=0;
          int zhenque=0;
          for(Integer list2:list1){
              System.out.println(list2);
              if(list2==0){
                  cuowu++;
              }else {
                  zhenque++;
              }
          }
          BhUser bhUser2=bhUserDao.chaa(bhUser.getuID());
          request.setAttribute("list",list);
          request.setAttribute("bhUser",bhUser2);
            request.setAttribute("zhengque",zhenque);
            request.setAttribute("cuwu",cuowu);
          request.getRequestDispatcher("/WEB-INF/jsp/Achievement.jsp").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    protected void xiang(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           String url=request.getParameter("das");
            BhcaseDao bhcaseDao=new  BhcaseDaoImpl();
            UsecasetrueDao usercasenum=new UsecasetrueDaoImpl();
            BhcasetmDao bhcasetmDao=new BhcasetmDaoImpl();
            HttpSession session=request.getSession();
            BhUser bhUser=(BhUser) session.getAttribute("BhSyUser");
        try {
            List<Bhcase> list= bhcaseDao.queryBhcase("select * from bhcase");
            List<Usecasetrue> list2=usercasenum.queryUsecasetrue("select * from usecasetrue where cUrl='"+url+"' and uID="+bhUser.getuID());
            List<Bhcasetm> list3=bhcasetmDao.queryBhcasetm("select * from usecasetrue where cUrl='"+url+"'");
            Usecasetrue use=usercasenum.queryUsecasetrue("select * from usecasetrue WHERE cUrl='"+url+"' and uID="+bhUser.getuID()).get(0);
            String ctrue[] = StringManipulation.stringFanXieGang(use.getcTrue());//答案
            request.setAttribute("list",list);
            request.setAttribute("list2",list2);

        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/WEB-INF/jsp/Xiangkao.jsp").forward(request,response);
    }

}
